//
//  EaseBubbleView+Goods.m
//  FlyingEagle
//
//  Created by Lj on 2017/6/5.
//  Copyright © 2017年 lj. All rights reserved.
//

#import "EaseBubbleView+Goods.h"
#import "CustomCellView_Goods.h"

#import "EaseMessageCell.h"

@implementation EaseBubbleView (Goods)

- (void)_setupWorkBubbleMarginConstraints
{
    NSLayoutConstraint *marginTopConstraint = [NSLayoutConstraint constraintWithItem:self.goodsView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0 constant:self.margin.top];
    NSLayoutConstraint *marginBottomConstraint = [NSLayoutConstraint constraintWithItem:self.goodsView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-self.margin.bottom];
    NSLayoutConstraint *marginLeftConstraint = [NSLayoutConstraint constraintWithItem:self.goodsView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1.0 constant:-self.margin.right];
    NSLayoutConstraint *marginRightConstraint = [NSLayoutConstraint constraintWithItem:self.goodsView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:self.margin.left];
    
    [self.marginConstraints removeAllObjects];
    [self.marginConstraints addObject:marginTopConstraint];
    [self.marginConstraints addObject:marginBottomConstraint];
    [self.marginConstraints addObject:marginLeftConstraint];
    [self.marginConstraints addObject:marginRightConstraint];
    
    [self addConstraints:self.marginConstraints];
}
- (void)setupWorkBubbleView {
//    self.goodsView = [[[NSBundle mainBundle] loadNibNamed:@"CustomCellView_Work" owner:self options:nil] firstObject];
    self.backgroundImageView.hidden = NO;

    
    self.goodsView = [[CustomCellView_Goods alloc]init];
    self.goodsView.translatesAutoresizingMaskIntoConstraints = NO;
    self.goodsView.backgroundColor = [UIColor clearColor];
    self.goodsView.layer.cornerRadius = 5;
    self.goodsView.clipsToBounds = YES;
    [self addSubview:self.goodsView];
    
    self.leftArrow = ({
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(-3, 10, 6, 6)];
        //        view.backgroundColor = [UIColor colorWithHexString:@"#33B7A5"];
        
        view;
    });
    [self addSubview:self.leftArrow];
    
    self.rightArrow = ({
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake([EaseMessageCell appearance].bubbleMaxWidth-3, 10, 6, 6)];
        //        view.backgroundColor = [UIColor colorWithHexString:@"#33B7A5"];
        
        view;
    });
    [self addSubview:self.rightArrow];
    
    self.leftArrow.transform = CGAffineTransformMakeRotation(M_PI_4);
    self.rightArrow.transform = CGAffineTransformMakeRotation(M_PI_4);
    
    
    [self.goodsView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
        make.width.mas_equalTo([EaseMessageCell appearance].bubbleMaxWidth);
    }];
    
//    self.customReadLabel = ({
//        UILabel *label = [[UILabel alloc] init];
//        label.backgroundColor = [UIColor clearColor];
//        label.font = [UIFont systemFontOfSize:13.0];
//        label.textColor = [UIColor colorWithHexString:@"#666666"];
//        label.text = @"已读";
//        label;
//    });
//    [self addSubview:self.customReadLabel];
    
//    [self.customReadLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.width.mas_equalTo(80);
//        make.height.mas_equalTo(30);
//        make.left.equalTo(self.goodsView.mas_right).offset(5);
//        make.centerY.equalTo(self.goodsView.mas_centerY);
//    }];
}
- (void)updateWorkMargin:(UIEdgeInsets)margin {
//    if (_margin.top == margin.top && _margin.bottom == margin.bottom && _margin.left == margin.left && _margin.right == margin.right) {
//        return;
//    }
//    _margin = margin;
//    
//    [self removeConstraints:self.marginConstraints];
//    [self _setupWorkBubbleMarginConstraints];
}

@end
